﻿using G.APITest.Part;
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;

namespace APITest.VanclSign
{
    [System.ComponentModel.Composition.Export(typeof(G.APITest.Part.IAPIRequestPart))]
    public class Project : G.APITest.Part.NormalRequest
    {
        public Project()
        {
            this.ExtensionProjectProperties = new G.APITest.Config.KVPair[] 
            {
                new G.APITest.Config.KVPair(){ Key="APPKey",Value="2011092259"},
                new G.APITest.Config.KVPair(){ Key="APPSecret",Value="e44764cf1fd551809f0991e6157f3ef2"}
            };
        }

        protected override void DoSign(G.APITest.Config.APIProjectConfig config, G.APITest.Config.APIConfig api, System.Collections.Generic.Dictionary<string, string> paramDic)
        {
            base.DoSign(config, api, paramDic);
            var data = paramDic.OrderBy(c => c.Key);
            string str = string.Empty;
            foreach (var item in data)
            {
                str += item.Key + item.Value;
            }
            string signStr = config.ExtensionProjectProperties.First(c => c.Key == "APPSecret").Value + str;
            string sign = System.Security.Cryptography.MD5.GetHashString(signStr).ToLower();
            paramDic.Add("sign", sign);
            this.RaiseStatusCallBack("签名字符串：" + signStr);
            this.RaiseStatusCallBack("签名结果：" + sign);
        }
        //protected override void DoSign(G.APITest.Config.APIProjectConfig config, G.APITest.Config.APIConfig api, System.Collections.Generic.Dictionary<string, string> paramDic)
        //{
        //    var data = paramDic.OrderBy(c => c.Key);
        //    string str = string.Empty;
        //    foreach (var item in data)
        //    {
        //        str += item.Key + item.Value;
        //    }
        //    string signStr = config.ExtensionProjectProperties.First(c => c.Key == "APPSecret").Value + str;
        //    string sign = System.Security.Cryptography.MD5.GetHashString(signStr);
        //    paramDic.Add("sign", sign);
        //    this.RaiseStatusCallBack("签名字符串：" + signStr);
        //    this.RaiseStatusCallBack("签名结果：" + sign);
        //}
    }
}
